package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;

/**
 * Created by chenchangxing on 15/12/18.
 */
public class CategoryScreeningAdapter extends BaseExpandableListAdapter {

    LayoutInflater inflater;
    Context context;

    public CategoryScreeningAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getGroupCount() {
        return 3;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 3;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_category, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ViewHolderChild child;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_category_child, null);
            child = new ViewHolderChild(convertView);
            convertView.setTag(child);
        } else {
            child = (ViewHolderChild)convertView.getTag();
        }
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    class ViewHolderChild {
        @Bind(R.id.category_child)
        TextView categoryChild;

        ViewHolderChild (View view) {
            ButterKnife.bind(this, view);
        }
    }

    class ViewHolder {
        @Bind(R.id.category)
        TextView category;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
